package com.sdhs.costcontrol.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.costcontrol.domain.GcControlSettlementPayment;
import com.sdhs.costcontrol.service.IGcControlSettlementPaymentService;

/**
 * 项目结算Controller
 * 
 * @author wanglei
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/costcontrol/settlement")
public class GcControlSettlementPaymentController extends BaseController
{
    @Autowired
    private IGcControlSettlementPaymentService gcControlSettlementPaymentService;

    /**
     * 查询项目结算列表
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcControlSettlementPayment gcControlSettlementPayment)
    {
        startPage();
        List<GcControlSettlementPayment> list = gcControlSettlementPaymentService.selectGcControlSettlementPaymentList(gcControlSettlementPayment);
        return getDataTable(list);
    }

    /**
     * 导出项目结算列表
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:export')")
    @Log(title = "项目结算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcControlSettlementPayment gcControlSettlementPayment)
    {
        List<GcControlSettlementPayment> list = gcControlSettlementPaymentService.selectGcControlSettlementPaymentList(gcControlSettlementPayment);
        ExcelUtil<GcControlSettlementPayment> util = new ExcelUtil<GcControlSettlementPayment>(GcControlSettlementPayment.class);
        util.exportExcel(response, list, "项目结算数据");
    }

    /**
     * 获取项目结算详细信息
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcControlSettlementPaymentService.selectGcControlSettlementPaymentById(id));
    }

    /**
     * 新增项目结算
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:add')")
    @Log(title = "项目结算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcControlSettlementPayment gcControlSettlementPayment)
    {
        return success(gcControlSettlementPaymentService.insertGcControlSettlementPayment(gcControlSettlementPayment));
    }

    /**
     * 修改项目结算
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:edit')")
    @Log(title = "项目结算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcControlSettlementPayment gcControlSettlementPayment)
    {
        return toAjax(gcControlSettlementPaymentService.updateGcControlSettlementPayment(gcControlSettlementPayment));
    }

    /**
     * 删除项目结算
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:settlement:remove')")
    @Log(title = "项目结算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcControlSettlementPaymentService.deleteGcControlSettlementPaymentByIds(ids));
    }
}
